#!/bin/bash

#=======================================================================
# ga-getnew
# File ID: 8af4d956-f358-11e4-b717-000df06acc56
#
# Get new files from the last week (can be overridden) that haven't got 
# enough copies in git-annex yet, then execute a fast fsck to check that 
# the files have enough copies.
#
# Author: Øyvind A. Holm <sunny@sunbase.org>
# License: GNU General Public License version 2 or later.
#=======================================================================

progname=ga-getnew

msg() {
    echo
    echo ==== $progname: $*
}

toplevel="$(git rev-parse --show-toplevel)"
cd "$toplevel" || {
    echo $progname: $toplevel: Cannot chdir to top of repo >&2
    exit 1
}

git wait-until-clean -u

# Using backslash before { and } to suppress folding when editing this 
# file.
msg ga sync \{\{\{
ga sync 2>&1
echo $progname: ga sync \}\}\}

msg ga get --auto
git allfiles --since=1.week "$@" |
    strip-nonexisting |
    xargs -d \\n --no-run-if-empty ga get --auto

msg git allfiles --since=1.week $*
msg ga fsck --fast --quiet
git allfiles --since=1.week "$@" |
    strip-nonexisting |
    xargs -d \\n --no-run-if-empty ga fsck --fast --quiet

msg ga sync \{\{\{
ga sync 2>&1
echo $progname: ga sync \}\}\}
